/**
 * 
 */
package com.lazyshopkeeper.front.apiService.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lazyshopkeeper.front.apiService.IItemCatsService;
import com.lazyshopkeeper.front.common.Constant;
import com.taobao.api.ApiException;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.ItemCat;
import com.taobao.api.request.ItemcatsGetRequest;
import com.taobao.api.response.ItemcatsGetResponse;

/**
 * @author xuyuqi
 *
 */
@Service
public class ItemCatsService implements IItemCatsService {

	@Autowired
	private TaobaoClient client;
	
	@Override
	public List<ItemCat> getTopCatelogs() throws ApiException {
		return getChildCatelogs(0);
	}

	@Override
	public List<ItemCat> getChildCatelogs(long parentId) throws ApiException {
		ItemcatsGetRequest req=new ItemcatsGetRequest();
		req.setFields(Constant.FILDS_ITEMCAT);
		req.setParentCid(parentId);
		ItemcatsGetResponse response = client.execute(req);
		return response.getItemCats();
	}

}
